import {User} from "../types";

const users:User[]=[];

//原例子尚未加入export
export const addUser = (newUser: User)=>{
    users.push(newUser);
};

export const getUser = (user:User)=>{
    return users.find(
        (u)=>u.username == user.username && u.password == user.password
    );
}




// function getInformation(){
//     return new Promise((resolve,reject)=>{
//         connection.query('select * from app_groups','',(err,res)=>{
//             // console.log(res);
//             if ( err ) {
//                 reject( err )
//             } else {
//                 resolve( res )
//             }
//         })
//     });
// }


// app.post('/users',(req,res)=>{
//     const {username,password} = req.body;
//     if(!username?.trim() || !password?.trim() ){
//         return res.status(400).send("bad username or password");
//     } 
    
//     addUser({username:username,password:password});

//     return res.status(201).send("User has been created");
// });
// app.post('/login',(req,res)=>{
//     const {username,password} = req.body;
//     const found = getUser({username,password});

//     if(!found){
//         return res.status(401).send("Login failed");
//     }
    
//     return res.status(200).send("success");
// });
